<?php
function cpx_get_coupon_detail($cp_id, $comment_count, $show_store_link = false)
{
    $cp_name = get_post_field('post_title', $cp_id);
    $cp_content = get_post_field('post_content', $cp_id);
    $cp_type = get_post_meta($cp_id, 'coupon_type_metadata', true);
    $cp_used = get_post_meta($cp_id, 'cp_people_used_metadata', true);
    $coupon_code = get_post_meta($cp_id, 'coupon_code_metadata', true);
    $outlink_cp = home_url().'/'.get_option('aff_out_link_prefix_cp').'/'.$cp_id;

    $cp_exclusive = get_post_meta($cp_id, 'exclusive_metadata', true);

    $store_id = get_post_meta($cp_id, 'store_coupon_metadata', true);
    $store_link = get_permalink($store_id);
    $store_name = get_post_field('post_title',$store_id);
    $store_html_link = "| <a href='$store_link' title='View more coupons at $store_name'>$store_name</a>";

    $cp_content = $store_name.' coupon: '.$cp_content;
    if(!$cp_used)
        $cp_used = 0;
?>
    <div id="<?php echo $cp_id;?>" class="row-fluid data-cp" data-store="<?php echo $store_id;?>" data-current_url="<?php echo cpx_current_url();?>">
                            <?php cpx_vote_coupon($cp_id); ?>
                            <div class="span10 hotcoupon-info-store">
                                    <h3>
                                        <a rel="nofollow" class="coupon_title" href="<?php echo $outlink_cp; ?>" target="<?php echo $store_id;?>" title="<?php echo $cp_name;?>"><?php echo ($search_kw != ''?cpx_highligh_keyword($cp_name,$search_kw):$cp_name);?></a>
                                    </h3>

                                    <?php if($cp_type == 'free_shipping'):?>
                                        <span class="type_icon sale_icon">Free Shipping</span>
                                    <?php elseif($cp_type == 'code'): ?>
                                        <span class="type_icon sale_icon">Sale</span>
                                    <?php elseif($cp_type == 'promotion'): ?>
                                        <span class="type_icon sale_icon">Promotion</span>
                                    <?php endif; ?>
                                    <?php if(!empty($cp_exclusive)):?>
                                        <span class="type_icon exclusive_icon">Exclusive</span>
                                    <?php endif;?>

                                    <div class="row-fluid action-crux">
                                        <div class="action-mask span4">
                                                  <?php if($coupon_code == ''){ ?>
                                                      <span class="action-button get-deal">Get Deal</span>
                                                  <?php }else{?>
                                                      <span class="action-button get-code">
                                                          <div class="wrapper-code">
                                                              <p><?php echo $coupon_code;?></p>
                                                              <div class="wrapper-mask">Get Code</div>
                                                              <span class="mask"></span>
                                                          </div>
                                                      </span>
                                                  <?php }?>
                                        </div>
                                    </div>
                                    <div class="row-fluid info-descrip">
                                        <p class="description">
                                               <?php echo $cp_content; ?>
                                        </p>
                                    </div>
                                    <div class="row-fluid vopcoms">
                                         <span class="vopcom count"><?php echo $comment_count; ?></span>
                                         <span class="showcm cm-count">Show Comment</span>
                                        <?php
                                        if(current_user_can('edit_post', $cp_id))
                                        {
                                            echo edit_post_link('Edit This Coupon','<span>[','] Author: ',$cp_id);
                                            $author_id = get_post_field('post_author', $cp_id);
                                            echo the_author_meta('display_name', $author_id);
                                            echo ' | Rate: '.get_post_meta($cp_id, 'like_metadata',true).'/';
                                            echo (get_post_meta($cp_id,'dislike_metadata',true)?get_post_meta($cp_id,'dislike_metadata',true):'0');
                                            echo '</span>';
                                        }
                                        ?>
                                         <span class="lesscm cm-count" style="display: none;">Hidden Comment</span>
                                         <span><?php echo($show_store_link == true )?$store_html_link:''; ?></span>
                                    </div>
                            </div>
                            <!-- COMMENT -->
                            <div id="cm-<?php echo $cp_id;?>" class="row-fluid cm_form display-none">
                                        <?php
                                            global $current_user;
                                            if(!$current_user->ID){
                                                $user_id = '';
                                                $user_name = 'Anonymous';
                                                $user_email ='';
                                                $user_url ='';
                                            }else{
                                                $user_id = $current_user->ID;
                                                $user_name =$current_user->user_login;
                                                $user_email = $current_user->user_email;
                                                $user_url = $current_user->user_url;
                                            }
                                           $comment_author_IP = preg_replace( '/[^0-9a-fA-F:., ]/', '',$_SERVER['REMOTE_ADDR'] );
                                           $comment_agent = substr($_SERVER['HTTP_USER_AGENT'], 0, 254);
                                           $comment_date = current_time('mysql');
                                           $comment_date_gmt = current_time('mysql', 1);
                                        ?>
                                        <div class="respond">
                                            <h3 class="reply-title">
                                            Add Comment
                                            </h3>
                                                    <div class="row-fluid form-cm">
                                                        <p class="comment-form-comment">
                                                            <textarea class="commentTxt" name="comment_content<?php echo $cp_id;?>" aria-required="true"></textarea>
                                                        </p>
                                                        <p onclick="submit_cm(<?php echo $cp_id;?>);" class="submit_comment">Post comment
                                                            <input type="hidden" name="comment_post_ID<?php echo $cp_id;?>" value="<?php echo $cp_id;?>">
                                                            <input type="hidden" name="comment_author_IP<?php echo $cp_id;?>" value="<?php echo $comment_author_IP;?>">
                                                            <input type="hidden" name="comment_agent<?php echo $cp_id;?>" value="<?php echo $comment_agent;?>">
                                                            <input type="hidden" name="comment_date<?php echo $cp_id;?>" value="<?php echo $comment_date;?>">
                                                            <input type="hidden" name="comment_date_gmt<?php echo $cp_id;?>" value="<?php echo $comment_date_gmt;?>">
                                                            <input type="hidden" name="user_id<?php echo $cp_id;?>" value="<?php echo $user_id;?>">
                                                            <input type="hidden" name="comment_author<?php echo $cp_id;?>" value="<?php echo $user_name;?>">
                                                            <input type="hidden" name="comment_author_email<?php echo $cp_id;?>" value="<?php echo $user_email;?>">
                                                            <input type="hidden" name="user_url<?php echo $cp_id;?>" value="<?php echo $user_url;?>">
                                                        </p>
                                                    </div>
                                        </div>
                                        <ol class="commentlist" id="commentlist<?php echo $cp_id;?>">
                                             <?php
                                                    $comments = get_comments(array(
                                                            'post_id' => $cp_id,
                                                            'status' => 'approve'
                                                    ));
                                                    wp_list_comments(array(
                                                            'per_page' => -1,
                                                            'reverse_top_level' => false,
                                                            'reply_text' => false,
                                                            'callback' => 'bigsave_comment'
                                                       ),
                                                       $comments);
                                            ?>
                                        </ol>
                                    </div>
                                    <!-- END COMMENT -->
    </div>
    <hr/>
<?php
}
?>